#include "stdafx.h"
#include "Platform.h"


#ifdef _WINDOWS
	#include "WinWindow.h"
#endif

#ifdef _LINUX
	#include "LinuxWindow.h"
#endif


XLIBRARY XApi::LoadLibrary(const char* libName)
{
	return ::LoadLibrary(libName);
}

void* XApi::GetProcAddress(XLIBRARY hLib, const char* procName)
{
	return ::GetProcAddress(reinterpret_cast<HMODULE>(hLib), procName);
}

IWindow* XApi::CreateWindowX(XINSTANCE appHandle, void* pMsgProc)
{
	IWindow* pWnd = new CPlatformWindow();
	if (!pWnd->Init(appHandle, pMsgProc))
		SAFE_DELETE(pWnd);

	return pWnd;
}

void XApi::SetCurrentDirectory(const char* dir)
{
	::SetCurrentDirectory(dir);
}

const char*	XApi::GetApplicationPath()
{
	HMODULE hModule = ::GetModuleHandle(nullptr);

	static char path[MAX_PATH];
	::GetModuleFileName(hModule, path, MAX_PATH);
	return path;
}

uint XApi::GetScreenWidth()
{
	return GetSystemMetrics(SM_CXSCREEN);
}

uint XApi::GetScreenHeight()
{
	return GetSystemMetrics(SM_CYSCREEN);
}

uint64 XApi::QueryPerformanceCounter()
{
	LARGE_INTEGER counter;
	QueryPerformanceCounter(&counter);
	return counter.QuadPart;
}

uint64 XApi::QueryPerformanceFrequency()
{
	LARGE_INTEGER frequency;
	QueryPerformanceFrequency(&frequency);
	return frequency.QuadPart;
}